<?php

namespace App\Http\Controllers\Article\Internal;

use App\Http\Controllers\BaseController;
use App\Service\Article\ArticleOperateService;
use Illuminate\Http\Request;

class ArticleController extends BaseController
{
    public function articleTop(Request $request)
    {
        $date  = $request->get('date');
        $limit = $request->get('limit', 10);

        $this->validate($request, [
            'date'  => 'required|date',
            'limit' => 'integer',
        ]);

        // 热门内容TOP
        $articleTop = ArticleOperateService::getTopArticleByDate($date, $limit);

        // 内容点击数据
        $click          = ArticleOperateService::getClickRedisData(date('Ymd', strtotime($date)));
        $clickYesterday = ArticleOperateService::getClickRedisData(date('Ymd', strtotime($date . ' -1 day')));

        return $this->success([
            'articleTop'     => $articleTop,
            'click'          => $click,
            'clickYesterday' => $clickYesterday,
        ]);
    }
}
